package courseScheduler;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJPanel1.java
 *
 * Created on Apr 14, 2011, 2:24:25 PM
 */

/**
 *
 * @author lyn5023
 */
public class AdvLoginPanel extends javax.swing.JPanel {

    /** Creates new form NewJPanel1 */
    public AdvLoginPanel() {
        initComponents();
        Config configFile=new Config();
        String[] args=new String[3];
        args=configFile.recoverConfigFile();
        if(!(configFile.recoverConfigFile()==null)){
            txtServerAddressInput.setText(args[0]);
            txtUserNameInput.setText(args[1]);
            txtPasswordInput.setText(args[2]);
            txtPortInput.setText(args[3]);
            chkSaveConnection.setSelected(true);
        }
        else{
            args=null;
            configFile=null;
            System.gc();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtPasswordDisplay = new javax.swing.JTextField();
        txtUserNameInput = new javax.swing.JTextField();
        txtPasswordInput = new javax.swing.JPasswordField();
        chAdvanced = new javax.swing.JCheckBox();
        txtUserNameDisplay = new javax.swing.JTextField();
        btnOk = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        txtServerAddressDisplay = new javax.swing.JTextField();
        txtServerAddressInput = new javax.swing.JTextField();
        txtPortDisplay = new javax.swing.JTextField();
        txtPortInput = new javax.swing.JTextField();
        chkSaveConnection = new javax.swing.JCheckBox();

        txtPasswordDisplay.setBackground(new java.awt.Color(192, 192, 192));
        txtPasswordDisplay.setText("Password");

        chAdvanced.setText("Advanced");

        txtUserNameDisplay.setBackground(new java.awt.Color(192, 192, 192));
        txtUserNameDisplay.setText("User Name");

        btnOk.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnOk.setText("OK");
        btnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkActionPerformed(evt);
            }
        });

        btnClear.setText("Clear");

        btnCancel.setText("Cancel");

        txtServerAddressDisplay.setBackground(new java.awt.Color(192, 192, 192));
        txtServerAddressDisplay.setText("Server Address");

        txtPortDisplay.setBackground(new java.awt.Color(192, 192, 192));
        txtPortDisplay.setText("Port");

        chkSaveConnection.setText("Save Connection");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(chAdvanced)
                        .addGap(46, 46, 46))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(btnOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnClear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(chkSaveConnection)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(txtServerAddressDisplay, 0, 0, Short.MAX_VALUE)
                            .addGap(169, 169, 169))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtServerAddressInput, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(txtPortDisplay)
                                    .addGap(31, 31, 31)
                                    .addComponent(txtPortInput, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(25, 25, 25))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtPasswordDisplay)
                                        .addComponent(txtUserNameDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(36, 36, 36)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtPasswordInput)
                                        .addComponent(txtUserNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGap(25, 25, 25))))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUserNameDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUserNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPasswordDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPasswordInput, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chAdvanced))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(txtServerAddressDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtServerAddressInput, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPortDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPortInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkSaveConnection)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOk)
                    .addComponent(btnClear)
                    .addComponent(btnCancel))
                .addContainerGap(32, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
        if(chkSaveConnection.isSelected()){
            char[] pass=new char[txtPasswordInput.getPassword().length];
            pass=txtPasswordInput.getPassword();
            String bPass=String.copyValueOf(pass);
            Config configFile=new Config(txtServerAddressInput.getText(),txtUserNameInput.getText(), bPass);
            configFile.generateConfigFile();
        }
    }//GEN-LAST:event_btnOkActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnClear;
    private javax.swing.JButton btnOk;
    private javax.swing.JCheckBox chAdvanced;
    private javax.swing.JCheckBox chkSaveConnection;
    private javax.swing.JTextField txtPasswordDisplay;
    private javax.swing.JPasswordField txtPasswordInput;
    private javax.swing.JTextField txtPortDisplay;
    private javax.swing.JTextField txtPortInput;
    private javax.swing.JTextField txtServerAddressDisplay;
    private javax.swing.JTextField txtServerAddressInput;
    private javax.swing.JTextField txtUserNameDisplay;
    private javax.swing.JTextField txtUserNameInput;
    // End of variables declaration//GEN-END:variables

}
